﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PRO_DOCS.DAL.Database;
using System.Data;

namespace PRO_DOCS.DAL.AppCode
{
    public class SearchResults : MainClass
    {
        public DataSet GET_SIMPLE_SEARCH_RESULTS(
            string sEARCH_KEY_WORD,
            bool fROM_DOCUMENT_BARCODE,
            bool fROM_DOCUMENT_NAME,
            bool fROM_FOLDER_NAME,
            bool fROM_DOCUMENT_EXTENSION,
            bool fROM_DOCUMENT_INDEX,
            bool fROM_DOCUMENT_NOTES,
            bool fROM_DOCUMENT_TYPE,
            bool fROM_OCR_RESULTS,
            string fROM_FOLDERS_IDS)
        {
            Dictionary<string, string> sqlParams = new Dictionary<string, string>();
            sqlParams.Add("@SEARCH_KEY_WORD", sEARCH_KEY_WORD);
            sqlParams.Add("@FROM_DOCUMENT_BARCODE", fROM_DOCUMENT_BARCODE.ToString());
            sqlParams.Add("@FROM_DOCUMENT_NAME", fROM_DOCUMENT_NAME.ToString());
            sqlParams.Add("@FROM_FOLDER_NAME", fROM_FOLDER_NAME.ToString());
            sqlParams.Add("@FROM_DOCUMENT_EXTENSION", fROM_DOCUMENT_EXTENSION.ToString());
            sqlParams.Add("@FROM_DOCUMENT_INDEX", fROM_DOCUMENT_INDEX.ToString());
            sqlParams.Add("@FROM_DOCUMENT_NOTES", fROM_DOCUMENT_NOTES.ToString());
            sqlParams.Add("@FROM_DOCUMENT_TYPE", fROM_DOCUMENT_TYPE.ToString());
            sqlParams.Add("@FROM_OCR_RESULTS", fROM_OCR_RESULTS.ToString());
            sqlParams.Add("@FROM_FOLDERS_IDS", fROM_FOLDERS_IDS);
            DataSet dsResult = getDataSet
                (
                    "GET_SIMPLE_SEARCH_RESULTS",
                    sqlParams
                );
            return dsResult;
        }

        public DataSet GET_ADVANCED_SEARCH_RESULTS(
            string aRCHIVE_DOCUMENT_TYPE_ID,
            string iNCLUDE_PREVIOUS_VERSIONS,
            string cREATED_BY_USER,
            string cREATED_BY_DATE,
            string cREATED_BY_OPERATION,
            string lAST_MODIFIED_BY_USER,
            string lAST_MODIFIED_BY_DATE,
            string lAST_MODIFIED_BY_OPERATION,
            string fROM_FOLDERS_IDS)
        {
            Dictionary<string, string> sqlParams = new Dictionary<string, string>();
            sqlParams.Add("@ARCHIVE_DOCUMENT_TYPE_ID", aRCHIVE_DOCUMENT_TYPE_ID);
            sqlParams.Add("@INCLUDE_PREVIOUS_VERSIONS", iNCLUDE_PREVIOUS_VERSIONS);
            sqlParams.Add("@CREATED_BY_USER", cREATED_BY_USER);
            sqlParams.Add("@CREATED_BY_DATE", cREATED_BY_DATE);
            sqlParams.Add("@CREATED_BY_OPERATION", cREATED_BY_OPERATION);
            sqlParams.Add("@LAST_MODIFIED_BY_USER", lAST_MODIFIED_BY_USER);
            sqlParams.Add("@LAST_MODIFIED_BY_DATE", lAST_MODIFIED_BY_DATE);
            sqlParams.Add("@LAST_MODIFIED_BY_OPERATION", lAST_MODIFIED_BY_OPERATION);
            sqlParams.Add("@FROM_FOLDERS_IDS", fROM_FOLDERS_IDS);
            DataSet dsResult = getDataSet
                (
                    "GET_ADVANCED_SEARCH_RESULTS",
                    sqlParams
                );

            DataRow _sEARCH_SQL_SCRIPT = dsResult.Tables[0].Rows[0];
            string SEARCH_SQL_SCRIPT = _sEARCH_SQL_SCRIPT[0].ToString();

            
            sqlParams = new Dictionary<string, string>();
            sqlParams.Add("@TEXT_SQL_QUERY", SEARCH_SQL_SCRIPT);
            DataSet dsExecutedScriptResult = getDataSet
                (
                    "EXECUTE_TEXT_SQL_QUERY",
                    sqlParams
                );

            return dsExecutedScriptResult;
        }

    }
}
